package com.mapapp.flutter_mapapp.http;

public class ApiException extends RuntimeException {

    public static final int USER_NOT_EXIST = 10002;

    private String message;
    private Integer code;

    public ApiException(Integer code, String detailMessage) {
        super(detailMessage);
        this.message =detailMessage;
        this.code = code;
    }

    public ApiException(String detailMessage) {
        super(detailMessage);
        this.message =detailMessage;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public Integer getCode() {
        return code;
    }
    /**
     * 由于服务器传递过来的错误信息直接给用户看的话，用户未必能够理解
     * 需要根据错误码对错误信息进行一个转换，在显示给用户
     * @param code
     * @return
     */
//    private static String getApiExceptionMessage(int code){
//        switch (code) {
//            case USER_NOT_EXIST:
//                message = "用户不存在";
//
//            default:
//                message = "未知错误";
//        }
//        return message;
//    }
}
